package ttOrder.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ttOrder.dao.inter.FoodMapper;
import ttOrder.model.po.Food;
import ttOrder.model.po.FoodType;
import ttOrder.model.vo.FoodVO;


@Service
@Transactional
public class FoodServiceImpl extends abstractService<Food>{

	@Autowired
	private FoodMapper foodMapper;
	@Resource
	private FoodTypeServiceImpl foodtypeservice;
	
	/* operate with vo class */
	
	public List<FoodVO> getMenu() {
		List<FoodVO> volist = new ArrayList<FoodVO>();
		List<Food> polist = foodMapper.selectAll();
		FoodVO vo = null;
		for (Food food : polist) {
			if (food.getMenuStatus() == 1) {
				vo = new FoodVO();
				BeanUtils.copyProperties(food, vo);
				vo.setFoodType(foodtypeservice.getByKey(new FoodType(food.getFoodTypeId())));
				volist.add(vo);
			}
		}
		return volist;
	}
	
	public FoodVO getByKey(FoodVO keyvo) {
		FoodVO vo = new FoodVO();
		if (keyvo != null) {
			Food key = new Food();
			BeanUtils.copyProperties(keyvo, key);
			Food po = new Food();
			po = foodMapper.selectByPrimaryKey(key);
			BeanUtils.copyProperties(po, vo);
		}
		return vo;
	}
	
	/* operate with po class */

	@Override
	public List<Food> getAll() {
		return foodMapper.selectAll();
	}

	@Override
	public List<Food> getByEntity(Food record) {
		return foodMapper.select(record);
	}

	@Override
	public Food getByKey(Food key) {
		return foodMapper.selectByPrimaryKey(key);
	}

	@Override
	public int insert(Food record) {
		return foodMapper.insert(record);
	}

	@Override
	public int update(Food record) {
		return foodMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int deleteByKey(Food key) {
		return foodMapper.deleteByPrimaryKey(key);
	}

	@Override
	public int deleteByEntity(Food record) {
		return foodMapper.delete(record);
	}

	@Override
	public int getCount(Food record) {
		return foodMapper.selectCount(record);
	}

}
